package demo01;

import java.util.HashMap;
import java.util.Map;

/**
 * 第一题: 通过代码, 完成如下需求:
 * 1. 创建HashMap集合, 键是学号(String), 值是学生对象(Student).		//姓名, 年龄.
 * 2. 往HashMap集合中添加3组数据.
 * 3. 通过两种方式, 遍历HashMap集合.
 */
public class demo01 {
    public static void main(String[] args) {
        //创建HashMap集合, 键是学号(String), 值是学生对象(Student).
        HashMap<String, Student> hs = new HashMap<String, Student>();

        //往HashMap集合中添加3组数据.
        hs.put("001", new Student("jack", 20));
        hs.put("002", new Student("tom", 20));
        hs.put("003", new Student("jerry", 20));

        //通过两种方式, 遍历HashMap集合.

        for (String s : hs.keySet()) {
            System.out.println(s + "..." + hs.get(s));
        }

        System.out.println("-----------------------------------");
        for (Map.Entry<String, Student> entry : hs.entrySet()) {
            System.out.println(entry.getKey() + "..." + entry.getValue());
        }

        System.out.println("-----------------------------------");
        hs.forEach((key, value) -> System.out.println(key + "---" + value));
    }
}
